package com.software.graduationproject.modules.user.service;


import cn.hutool.extend.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.Page;


import com.software.graduationproject.commons.exception.ServiceException;
import com.software.graduationproject.commons.select.Select;
import com.software.graduationproject.modules.user.entity.UserAddress;
import com.software.graduationproject.modules.user.mapper.UserAddressMapper;
import com.software.graduationproject.modules.user.object.UserAddressVo;
import com.software.graduationproject.modules.user.object.UserAddressCreateQo;
import com.software.graduationproject.modules.user.object.UserAddressUpdateQo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;




import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * UserAddressService : 用户地址表
 * ---------------------------------------------------------------------------------------------------------------------
 */
@Service
public class UserAddressService {

    @Autowired
    private UserAddressMapper userAddressMapper;

    public void createQo(UserAddressCreateQo qo){
        UserAddress userAddress = new UserAddress();
        BeanUtil.copyPropertiesNotNull(qo, userAddress);
        userAddressMapper.insert(userAddress);
    }

    public void updateQo(UserAddressUpdateQo qo){
        UserAddress userAddress = userAddressMapper.selectById(qo.getId());
        if (userAddress == null){
            throw  new ServiceException("数据不存在");
        }
        BeanUtil.copyPropertiesNotNull(qo, userAddress);
        userAddressMapper.updateById(userAddress);
    }
//
//    public UserAddressVo selectVo(Long id) {
//        UserAddressVo userAddressVo = new UserAddressVo();
//        UserAddress userAddress = userAddressMapper.select(id);
//        Beans.copyPropertiesNotNull(userAddressVo, userAddress);
//        return userAddressVo;
//    }

    public void delete(Long id) {
        userAddressMapper.deleteById(id);
    }

    public Page<UserAddressVo> selectPageVo(Select select){
        return userAddressMapper.selectPageVo(select);
    }

    public List<UserAddressVo> selectListVo(Select select){
        return userAddressMapper.selectListVo(select);
    }
}
